//
//  BaoMinTableViewController.m
//  MagazineShangejie
//
//  Created by cnbizMedia on 15/9/25.
//  Copyright © 2015年 CnbizMedia. All rights reserved.
//

#import "BaoMinTableViewController.h"
#import "Util.h"
@interface BaoMinTableViewController (){
    NSInteger number;
    NSInteger rowNumber;
    NSInteger textFieldNumber;
    NSInteger textViewNumber;
    NSInteger humanNumber;
    NSInteger moneyNumber;
    
    UITableViewCell *cell ;
    NSArray *nameArray;
    NSArray *photoArray;
    
    UITextView * textView;
    UILabel    * numberLabel;
    UITextField * moneyTextField;
}

@end

@implementation BaoMinTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *okAButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-120, self.view.frame.size.width, 50)];
    [okAButton addTarget:self action:@selector(okPush) forControlEvents:UIControlEventTouchUpInside];
    okAButton.titleLabel.text = @"提交";
    okAButton.titleLabel.textColor = [UIColor whiteColor];
    okAButton.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:okAButton];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //2. 取出数据
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    number = [userDefault integerForKey:@"buttonTagNumber"];
    
    
    switch (number) {
        case 0:
            self.title = @"论坛报名";
            rowNumber = 3;
            textFieldNumber = 2;
            textViewNumber  = 0;
            humanNumber     = 1;
            moneyNumber     = 0;
            nameArray = @[@"姓名",@"电话"];
            photoArray = @[@"User01",@"phone"];
            break;
            
        case 1:
            self.title = @"游学报名";
            rowNumber = 3;
            textFieldNumber = 2;
            textViewNumber  = 0;
            humanNumber     = 1;
            moneyNumber     = 0;
            nameArray = @[@"姓名",@"电话"];
            photoArray = @[@"User01",@"phone"];
            break;
            
        case 2:
            self.title = @"咨询报名";
            rowNumber = 4;
            textFieldNumber = 4;
            textViewNumber  = 1;
            humanNumber     = 0;
            moneyNumber     = 1;
            nameArray = @[@"企业名称",@"所属行业",@"姓名",@"电话"];
            photoArray = @[@"icon01",@"icon3",@"User01",@"phone"];
            break;
            
        case 3:
            self.title = @"创投报名";
            rowNumber = 4;
            textFieldNumber = 2;
            textViewNumber  = 1;
            humanNumber     = 0;
            moneyNumber     = 1;
            nameArray = @[@"姓名",@"电话"];
            photoArray = @[@"User01",@"phone"];
            break;
            
        case 4:
            self.title = @"咨询报名";//永道招商
            rowNumber = 4;
            textFieldNumber = 4;
            textViewNumber  = 1;
            humanNumber     = 0;
            moneyNumber     = 1;
            nameArray = @[@"企业名称",@"所属行业",@"姓名",@"电话"];
            photoArray = @[@"icon01",@"icon3",@"User01",@"phone"];
            break;
            
        case 5:
            self.title = @"咨询报名";//智放
            rowNumber = 4;
            textFieldNumber = 4;
            textViewNumber  = 1;
            humanNumber     = 0;
            moneyNumber     = 1;
            nameArray = @[@"企业名称",@"所属行业",@"姓名",@"电话"];
            photoArray = @[@"icon01",@"icon3",@"User01",@"phone"];
        default:
            break;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 5;
 
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
       if (section==0) {
            return textFieldNumber;
        }else if (section==1){
            return textViewNumber;
        }else if (section==2){
            //        return 2;
            return humanNumber;
        }
        else if (section==3){
            return moneyNumber;
        }
        else if (section==4){
            return 1;
        }
        
        else{
            return 0;
        }
   
    return 0;
 
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section==0) {
        
            return 107;
 
    }
    
    else if (indexPath.section==1){
        
                return 120;
        
    }
    
    else if(indexPath.section==2){
        return 120;
    }
    
    else if(indexPath.section==3){
        return 120;
    }
    
    else if(indexPath.section==4){
        return 43;
    }
 
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.section==0){
       
        cell = [tableView dequeueReusableCellWithIdentifier:@"oneTextFieldCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"oneTextFieldCell"];
        }
        
//        if (number == 0 || number == 1 || number == 3) {
        
            UILabel *nameLabel = (UILabel *)[cell.contentView viewWithTag:11];
            nameLabel.text = nameArray[indexPath.row];
            
            
            UIImageView*imageView=(UIImageView*)[cell.contentView viewWithTag:22];
            imageView.image = [UIImage imageNamed:photoArray[indexPath.row]];
            
            UITextField *textField = (UITextField *)[cell.contentView viewWithTag:33];
            textField.placeholder = [NSString stringWithFormat:@"请输入%@",nameLabel.text];
            
            cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
            
            return cell;
//        }
        
      
    }
    
    else if (indexPath.section == 1){
        
        cell = [tableView dequeueReusableCellWithIdentifier:@"textViewCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"textViewCell"];
        }
        
        UILabel *title = (UILabel *)[cell.contentView viewWithTag:11];
        if (number == 2) {
            title.text = @"合作意向";
        }
        
        textView = (UITextView *)[cell.contentView viewWithTag:22];
        
        
        
        cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
        
        
        
        return cell;
        
    }
    
    
    else if (indexPath.section == 2){
        
        cell.userInteractionEnabled = YES;
        cell = [tableView dequeueReusableCellWithIdentifier:@"humanCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"humanCell"];
        }
        
        
        UIButton *downButton = (UIButton *)[cell.contentView viewWithTag:1];
        
        [downButton setImage:[UIImage imageNamed:@"down"] forState:UIControlStateNormal];
        [downButton addTarget:self action:@selector(downManNumber) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *upButton = (UIButton *)[cell.contentView viewWithTag:3];
        
        [upButton setImage:[UIImage imageNamed:@"up"] forState:UIControlStateNormal];
        [upButton addTarget:self action:@selector(upManNumber) forControlEvents:UIControlEventTouchUpInside];
        
        
        numberLabel = (UILabel *)[cell.contentView viewWithTag:2];
        numberLabel.text = @"0";
        
        tableView.delaysContentTouches = NO;
        
        cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
        
        
        
        return cell;
        
    }
    
    else if (indexPath.section == 3){
        
        cell = [tableView dequeueReusableCellWithIdentifier:@"moneyTextCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"moneyTextCell"];
        }
        
        moneyTextField = (UITextField *)[cell.contentView viewWithTag:11];
        
        
        return cell;
        
    }
    
    
    else if (indexPath.section == 4){
        
        cell = [tableView dequeueReusableCellWithIdentifier:@"tijiaoCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"tijiaoCell"];
        }
        
        UIButton *OKButton = (UIButton *)[cell.contentView viewWithTag:1];
        [OKButton addTarget:self action:@selector(okPush) forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
        
    }
    //    }
    
    cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
    
    
    
    return cell;
}

//提交
- (void)okPush{

    
}

- (void)upManNumber  {
    numberLabel.text = [NSString stringWithFormat:@"%ld",[numberLabel.text integerValue] + 1];
}

- (void)downManNumber  {
    if ([numberLabel.text integerValue] == 0) {
        return;
    }
    
    else {
        numberLabel.text = [NSString stringWithFormat:@"%ld",[numberLabel.text integerValue] - 1];
    }
}


@end
